const db = require("./db");
/**
 * 插入电视台数据
 */
exports.createTv = async (data) => {
  let sql = "insert into tv_list(title,url) values ?";
  let res = await db.insert(sql, data);
  return res;
};

/**
 * 获取电视台列表
 * @param {*} pageNo
 * @param {*} pageSize
 * @returns
 */
exports.queryTvList = async (pageNo, pageSize) => {
  let sql = "";
  if ((pageNo || pageNo === 0) && pageSize) {
    sql = `select * from tv_list limit ${pageNo},${pageSize}`;
  } else {
    sql = `select * from tv_list`;
  }

  let res = await db.query(sql);
  return res;
};


/**
 * 获取视频数据
 */
exports.queryVideoByUrl = async (url) => {
  let sql = `select * from video_list where source_url='${url}' `;
  let res = await db.query(sql);
  return res;
};

/**
 * 创建视频数据
 */
exports.createVideo = async (param) => {
  let sql = `insert into video_list(name,play_url,cid,source_url) value('${param.title}','${param.playUrl}','${param.cid}','${param.url}') `;
  let res = await db.insert(sql);
  return res;
};